home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Source / Dialog Item Stuff / SkelDlogBtnOutliner.c next >
Text File  |  1996-01-17  |  2KB  |  75 lines

  1. /*
  2.  * Associate a button-outlining function with the given item, which should
  3.  * be a user item.  The item outlined will be the default item, and should
  4.  * be a push button.  The user item bounding rectangle is positioned and
  5.  * sized to surround the default item.
  6.  *
  7.  * There's a subtle point here -- the outline drawing proc is called when the
  8.  * user item rect is becomes invalid, but the drawing proc bases its calculations
  9.  * on the rect for the default button item.  This works because the rect it
  10.  * calculates based on the button rect is identical to that of the user item.
  11.  *
  12.  * If you set the default button's hiliting state, you should redraw the outline
  13.  * as necessary to match the button.  (This can be accomplished by by invalidating
  14.  * the outline item's bounding rectangle.)  You can avoid unnecessary redrawing by
  15.  * drawing only when the button hiliting actually changes, like this:
  16.  *
  17.  *    if (SkelSetDlogCtlHilite (dlog, buttonItem, newHilite)
  18.  *    {
  19.  *        SkelGetDlogRect (dlog, outlineItem, &r);
  20.  *        InvalRect (&r);
  21.  *    }
  22.  *
  23.  * SkelSetDlogCtlHilite() returns true only if the control hiliting *changes*.
  24.  */
  25.  
  26. # include    "TransSkel.h"
  27.  
  28.  
  29. /*
  30.  * Draw heavy outline around default dialog button.
  31.  */
  32.  
  33. static pascal void
  34. DrawDlogButtonOutline (DialogPtr d, short item)
  35. {
  36.     SkelDrawButtonOutline (SkelGetDlogCtl (d, ((DialogPeek) d)->aDefItem));
  37. }
  38.  
  39.  
  40. /*
  41.  * For 68K a pointer to the drawing procedure DrawDlogButtonOutline() can
  42.  * be passed directly to SetDItem().  For PowerPC code a pointer to a
  43.  * routine descriptor must be passed instead.  The descriptor is allocated
  44.  * statically since it doesn't have to be deallocated.  (There's no way to
  45.  * tell when it would be safe to deallocate it anyway.)
  46.  */
  47.  
  48. # if skelPPC        /* PowerPC code */
  49. static RoutineDescriptor    drawDesc =
  50.         BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, DrawDlogButtonOutline);
  51. # endif
  52.  
  53.  
  54. pascal void
  55. SkelSetDlogButtonOutliner (DialogPtr d, short item)
  56. {
  57. short    type;
  58. Handle    h;
  59. Rect    r, rJunk;
  60. short    defItem;
  61.  
  62.     /* find default item bounding rectangle */
  63.     defItem = ((DialogPeek) d)->aDefItem;
  64.     GetDialogItem (d, defItem, &type, &h, &r);
  65.  
  66.     /* get user item, position rectangle, and install draw proc using it */
  67.     GetDialogItem (d, item, &type, &h, &rJunk);
  68.     InsetRect (&r, -4, -4);
  69. # if skelPPC        /* PowerPC code */
  70.     SetDialogItem (d, item, type, (Handle) &drawDesc, &r);
  71. # else                /* 68K code */
  72.     SetDialogItem (d, item, type, (Handle) DrawDlogButtonOutline, &r);
  73. # endif
  74. }
  75.